home *** CD-ROM | disk | FTP | other *** search
- #include "Painterly.h"
-
- /* Painterly Globals */
- extern MenuHandle gPaintMenuHandles[]; /* The menus we add */
- extern DocumentRecord gSrcDoc, gDstDoc; /* The doc records */
- extern CWindowPtr gSrcWindPtr, gDstWindPtr; /* pointers to the windows, for convenience */
- extern GWorldPtr gUndoBuffer; /* a buffer to allow undo */
- extern BrushParams gBrushStuff; /* the parameter structure for brush calls */
- extern THPrint gPrintRecHandle; /* The print record */
- extern short gDocTitleHeight, gDocFrameWidth; /* Window Stats */
- /* Prototypes for local (to this file) routines */
- Boolean AddStdScrollBars(WindowPtr wind);
- Boolean CheckMachine(void);
-
- /* Called by the Shell at startup time */
- Boolean PaintInit(void)
- {
- MenuHandle mhndl;
- Str255 brushname, wTitle;
- Rect temprect;
- short rslt;
-
- /* Check for the machine characteristics we need to run */
- if(CheckMachine() == false)
- {
- DoErrorAlert(kWimpyMachineStr, 0);
- return false;
- }
-
- /* Get the window measurements we'll need later */
- CalcWindowStats();
-
- /* Create the document windows. They remain invisible until a document is opened */
- SetRect(&temprect, 10, 10 + 20 + GetMBarHeight(), 210, 210 + 20 + GetMBarHeight());
- gSrcWindPtr = NewCWindow( (Ptr)&gSrcDoc,
- &temprect,
- TheStr(wTitle, kSrcPictStr),
- false,
- zoomDocProc,
- (WindowPtr)(-1),
- true, /* Only the source window has a close box */
- 0L );
- SetPort(gSrcWindPtr);
- ClipRect(&gSrcWindPtr->portRect);
- EraseRect(&gSrcWindPtr->portRect);
-
- OffsetRect(&temprect, 32, 32);
- gDstWindPtr = NewCWindow( (Ptr)&gDstDoc,
- &temprect,
- TheStr(wTitle, kArtStr),
- false,
- zoomDocProc,
- (WindowPtr)(-1),
- false,
- 0L );
- SetPort(gDstWindPtr);
- ClipRect(&gDstWindPtr->portRect);
- EraseRect(&gDstWindPtr->portRect);
-
- /* We don't create the GWorlds yet: that'll happen when the user opens a file */
-
- /* Set up the other Doc info */
- gSrcDoc.dirty = false;
- gDstDoc.dirty = false;
- *gSrcDoc.fileSpec.name = 0; /* make the file name an empty string */
- *gDstDoc.fileSpec.name = 0; /* make the file name an empty string */
- if(!AddStdScrollBars(gSrcWindPtr) || !AddStdScrollBars(gDstWindPtr))
- {
- DoErrorAlert(kNoResStr, 0);
- return false;
- }
-
- /* Set up the global BrushParams */
- gBrushStuff.pt.h = 0;
- gBrushStuff.pt.v = 0;
- gBrushStuff.rect = gSrcWindPtr->portRect;
- gBrushStuff.color.red = 0;
- gBrushStuff.color.green = 0;
- gBrushStuff.color.blue = 0;
- gBrushStuff.theSource = gSrcDoc.world;
- gBrushStuff.theDestination = gDstDoc.world;
- gBrushStuff.storage = (long)nil;
-
- /* make a print record */
- gPrintRecHandle = (THPrint)NewHandle(sizeof(TPrint));
- if(gPrintRecHandle != nil)
- {
- /* Fill it with default values */
- PrOpen();
- if(PrError() == noErr)
- {
- PrintDefault(gPrintRecHandle);
- PrClose();
- }
- }
-
- /* Set up Filter menu */
- mhndl = GetMenu(kFilterMenuID);
- if(mhndl == nil)
- {
- DoErrorAlert(kNoResStr, 0);
- return false;
- }
- (*mhndl)->menuID = kFilterMenuID;
- BuildFilterMenu(mhndl); /* Adds all available Filters to the menu */
- InsertMenu(mhndl, 0);
- DisableItem(mhndl, 0); /* Disable the menu until user opens a file */
- gPaintMenuHandles[kFilterMenu] = mhndl;
-
- /* Set up brush menu */
- mhndl = GetMenu(kBrushMenuID);
- if(mhndl == nil)
- {
- DoErrorAlert(kNoResStr, 0);
- return false;
- }
- (*mhndl)->menuID = kBrushMenuID;
- BuildBrushMenu(mhndl); /* Adds all available brushes to the menu */
- InsertMenu(mhndl, 0);
- DisableItem(mhndl, 0); /* Disable the menu until user opens a file */
- gPaintMenuHandles[kBrushMenu] = mhndl;
-
- /* Load the first Brush */
- rslt = SetCurrentBrush(kFirstBrush);
- if(rslt != noErr)
- {
- DoErrorAlert(kGenericErrorStr, 0);
- return false;
- }
-
- /* Set up auto-paint menu */
- mhndl = GetMenu(kAutoPaintMenuID);
- if(mhndl == nil)
- {
- DoErrorAlert(kNoResStr, 0);
- return false;
- }
- (*mhndl)->menuID = kAutoPaintMenuID;
- InsertMenu(mhndl, 0);
- DisableItem(mhndl, 0); /* Disable the menu until user opens a file */
- gPaintMenuHandles[kAutoPaintMenu] = mhndl;
-
- /* Update the menu bar */
- DrawMenuBar();
-
- return(true);
- }
-
- /* Adds 2 scroll bars to the given window, adjusting them to fit */
- Boolean AddStdScrollBars(WindowPtr wind)
- {
- ControlHandle scrollHandle;
- Rect scrollRect;
- short min, max;
- Boolean rslt = false;
-
- /* These are just dummy values for the rect and the min and max. They will be
- adjusted in the AdjustScrollBars routine */
-
- /* First the horizontal one */
- SetRect(&scrollRect, 0, 0, 10, 10);
- min = 0;
- max = 10;
- scrollHandle = NewControl(wind, &scrollRect, "\p", false,
- min, min, max, scrollBarProc, 0);
-
- if(scrollHandle != nil)
- {
- /* Stash it in the document */
- ((DocumentPeek)wind)->hScroll = scrollHandle;
-
- /* Now the vertical */
- scrollHandle = NewControl(wind, &scrollRect, "\p", false,
- min, min, max, scrollBarProc, 0);
- if(scrollHandle != nil)
- {
- /* Stash it in the document */
- ((DocumentPeek)wind)->vScroll = scrollHandle;
- rslt = true;
- }
- else
- DisposeControl(((DocumentPeek)wind)->hScroll);
- }
- if(rslt == true)
- {
- /* Set up the scroll bars for the current world */
- AdjustScrollbars(wind, true);
- }
- return rslt;
- }
-
- Boolean CheckMachine(void)
- {
- short err, rslt = true;
- long gestResult;
-
- /* Check the machine's capabilities to be sure we can run */
-
- /* Check for availability of Gestalt */
- if(!TrapAvailable(_GestaltDispatch))
- return false;
-
- /* Check for availability of GWorlds */
- err = Gestalt(gestaltQuickdrawVersion, &gestResult);
- if(err != noErr)
- return false;
- if(gestResult < 0x0200) /* no 32-bit QD */
- return false;
-
- /* Check for availability of FSSpec file routines */
- err = Gestalt(gestaltFSAttr, &gestResult);
- if(err != noErr)
- return false;
- if((gestResult & (1 << gestaltHasFSSpecCalls)) == 0)
- return false;
-
- /* Check for availability of Standard Get/Put routines */
- err = Gestalt(gestaltStandardFileAttr, &gestResult);
- if(err != noErr)
- return false;
- if((gestResult & (1 << gestaltStandardFile58)) == 0)
- return false;
-
- /* Check for availability of FindFolder routine */
- err = Gestalt(gestaltFindFolderAttr, &gestResult);
- if(err != noErr)
- return false;
- if((gestResult & (1 << gestaltFindFolderPresent)) == 0)
- return false;
-
- /* Check for availability of TempMem routines */
- err = Gestalt(gestaltOSAttr, &gestResult);
- if(err != noErr)
- return false;
- if((gestResult & (1 << gestaltTempMemSupport)) == 0)
- return false;
-
- return true;
- }
-
- /* This routine calculates a document window's title bar height and frame width, for
- later use in positioning and growing windows. (Did you know that GrowWindow() takes
- as limits the size of the window's strucRgn, but returns the size of its portRect?) */
-
- void CalcWindowStats(void)
- {
- WindowRecord tempWind;
- Rect globalPortRect, strucRect, offScreenRect, deskRect;
-
- /* Make a small rectangle that is off the screen */
- deskRect = (**GetGrayRgn()).rgnBBox;
- SetRect(&offScreenRect, 0, 0, 32, 32);
- OffsetRect(&offScreenRect, deskRect.left - 64, 0);
-
- /* Make a visible window that the user can't see. Only when a window is visible
- can you find out its strucRgn dimensions */
- NewWindow(&tempWind, &offScreenRect, "\p", true, documentProc, (Ptr)-1, false, 0);
-
- /* OK, we have a window. Now calculate the info we need. First we need
- to globalize the portRect and get the strucRect of the window */
- globalPortRect = ((GrafPtr)(&tempWind))->portRect;
- SetPort(&tempWind);
- LocalToGlobal(&topLeft(globalPortRect));
- LocalToGlobal(&botRight(globalPortRect));
- strucRect = (*(((WindowPeek)(&tempWind))->strucRgn))->rgnBBox;
-
- /* Calculate the window's title bar height. I'm not entirely sure why you need to
- subtract 1 here, but Craig Prouse did it in his Window Zoom routine, and I'm sure
- he had a good reason for it, so I'll do it too. */
- gDocTitleHeight = globalPortRect.top - 1 - strucRect.top;
-
- /* Calculate the width of the windows right side frame */
- gDocFrameWidth = strucRect.right - 1 - globalPortRect.right;
-
- /* All Done, kill the window */
- CloseWindow(&tempWind);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-